#include "ThData.h"

#include <float.h>
#include <limits.h>

#include "ComDefine.h"

bool CThData::IsCommNormal()
{
    return (0 == m_uCommState);
}

bool CThData::IsCommFault()
{
    return (1 == m_uCommState);
}

bool CThData::IsRunning()
{
    return (0 == m_uRunState);
}

bool CThData::IsStopped()
{
    return (1 == m_uRunState);
}

bool CThData::IsFault()
{
    return (1 == m_uFaultState);
}

bool CThData::IsNoFault()
{
    return (0 == m_uFaultState);
}

bool CThData::IsAlarm()
{
    return (1 == m_uAlarmState);
}

bool CThData::IsNoAlarm()
{
    return (0 == m_uAlarmState);
}

bool CThData::IsOpening()
{
    return (1 == m_uSwitchState);
}

bool CThData::IsClosed()
{
    return (0 == m_uSwitchState);
}

//获取***的显示文本
QString CThData::GetCommStateText()
{
    if (0xFFFF == m_uCommState)
    {
        return QObject::tr("---");
    }
    else if (1 == m_uCommState)
    {
        return QObject::tr("故障");
    }
    else
    {
        return QObject::tr("正常");
    }
}

void CThData::InitToInvalid()
{
    InitToValue(0xFFFF, FLT_MAX);
}

void CThData::InitToZero()
{
    InitToValue(0, 0.0);
}

void CThData::InitToValue(quint16 uvalue, float fvalue)
{
    m_uCommState = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = fvalue;
    }

    //转发的100个UINT16数据
    m_uRunState = uvalue;
    m_uFaultState = uvalue;
    m_uAlarmState = uvalue;
    m_uSwitchState = uvalue;
    m_uBacklightTimes = uvalue;      //背光时长

    m_uSensorState = uvalue;         //继电器状态
    m_uSystemUnit = uvalue;          //系统单位
    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = uvalue;
    }

    //转发的100个FLOAT数据
    m_fInsideTemp = fvalue;
    m_fInsideHumi = fvalue;
    m_fAdjustTemp = fvalue;            //温度校准值
    m_fAdjustHumi = fvalue;            //湿度校准值
    m_fTempUpLimit = fvalue;           //温度上限

    m_fTempDownLimit = fvalue;         //温度下限
    m_fHumiUpLimit = fvalue;           //湿度上限
    m_fHumiDownLimit = fvalue;         //湿度下限
    m_fTempDiff = fvalue;              //温度回差
    m_fHumiDiff = fvalue;              //湿度回差

    m_fInsideTemp1 = fvalue;            //室内温度1,单位为℃
    m_fInsideTemp2 = fvalue;            //室内温度2,单位为℃
    m_fInsideTemp3 = fvalue;            //室内温度3,单位为℃
    m_fInsideTemp4 = fvalue;            //室内温度4,单位为℃
    m_fInsideTemp5 = fvalue;            //室内温度5,单位为℃

    m_fInsideHumi1 = fvalue;            //室内湿度1,单位为%
    m_fInsideHumi2 = fvalue;            //室内湿度2,单位为%
    m_fInsideHumi3 = fvalue;            //室内湿度3,单位为%
    m_fInsideHumi4 = fvalue;            //室内湿度4,单位为%
    m_fInsideHumi5 = fvalue;            //室内湿度5,单位为%

    m_fTempPay = fvalue;               //温度补偿
    m_fHumiPay = fvalue;               //湿度补偿
    m_fCo2Pay = fvalue;                //CO2补偿
    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = fvalue;
    }

    m_fSetAdjustTemp = fvalue;            //设置温度校准值
    m_fSetAdjustTempCopy = fvalue;
    m_fSetAdjustHumi = fvalue;            //设置湿度校准值
    m_fSetAdjustHumiCopy = fvalue;
    m_fSetTempUpLimit = fvalue;           //温度上限
    m_fSetTempUpLimitCopy = fvalue;
    m_fSetTempDownLimit = fvalue;         //温度下限
    m_fSetTempDownLimitCopy = fvalue;
    m_fSetHumiUpLimit = fvalue;           //湿度上限
    m_fSetHumiUpLimitCopy = fvalue;

    m_fSetHumiDownLimit = fvalue;         //湿度下限
    m_fSetHumiDownLimitCopy = fvalue;
    m_fSetTempDiff = fvalue;              //温度回差
    m_fSetTempDiffCopy = fvalue;
    m_fSetHumiDiff = fvalue;              //湿度回差
    m_fSetHumiDiffCopy = fvalue;
    m_fSetTempPay = fvalue;               //温度补偿
    m_fSetTempPayCopy = fvalue;
    m_fSetHumiPay = fvalue;               //湿度补偿
    m_fSetHumiPayCopy = fvalue;

    m_fSetCo2Pay = fvalue;                //CO2补偿
    m_fSetCo2PayCopy = fvalue;
    for (int i = 0; i < ARRAYSIZE(m_fSetData); ++i)
    {
        m_fSetData[i] = fvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_fSetDataCopy); ++i)
    {
        m_fSetDataCopy[i] = fvalue;
    }

    m_uSetBacklightTimes = uvalue;      //设置背光时长
    m_uSetBacklightTimesCopy = uvalue;
    m_uSetSensorState = uvalue;         //设置继电器状态
    m_uSetSensorStateCopy = uvalue;
    m_uSetSystemUnit = uvalue;          //设置系统单位
    m_uSetSystemUnitCopy = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = uvalue;
    }
}
